import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
import path from 'path';
import PostcssPxToRem from 'postcss-pxtorem';
import { REM_BASE_SIZE } from './src/config/constant';

// 导出配置，指定类型为 UserConfig
export default defineConfig({
    plugins: [react()],
    resolve: {
        alias: {
            '@': path.resolve(__dirname, './src'),
        },
    },
    css: {
        postcss: {
            plugins: [PostcssPxToRem({ rootValue: REM_BASE_SIZE, propList: ['*'] })],
        },
        preprocessorOptions: {
            less: {
                javascriptEnabled: true,
                // additionalData: `@import "./src/styles/main.less";`,
            },
        },
    },
    optimizeDeps: {
        include: ['react', 'react-dom', 'antd', 'axios'],
    },
    build: {
        minify: 'terser',
        chunkSizeWarningLimit: 1024, // 单位kb，控制警告阈值
        rollupOptions: {
            output: {
                manualChunks: (id, api) => {
                    if (id.includes('node_modules/@micro-zoe/micro-app')) {
                        return 'micro-app';
                    }
                    return undefined;
                },
            },
        },
    },
});
